package dao;

import negocio.Factura;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import hbt.HibernateUtil;

public class FacturaDAO {

	private static FacturaDAO instancia = null;
	private static SessionFactory sf = null;
	
	public FacturaDAO()
	{
		
	}
	public static FacturaDAO getInstancia()
	{
		if (instancia==null)
		{
			sf = HibernateUtil.getSessionFactory();
			instancia = new FacturaDAO();
		}
		return instancia;
	}
	
	public void grabarFactura(Factura f)
	{
		Session s = sf.openSession();
		s.beginTransaction();
		s.persist(f);
		s.flush();
		s.getTransaction().commit();
		s.close();
	}

	public Factura buscarFactura(int nroFactura) {
		Session session = sf.openSession();
		Factura f = new Factura();
		f.setNroFactura(nroFactura);
		session.load(f, f.getNroFactura());			
		session.close();
		return f;
	}
}
